<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BAppPool
 *
 * @author ID59C
 */
class BAppPool {

    private $sApps = array();
    private $opps = array();
    private $isAppChanged = array();
    private $isOppChanged = array();
    private $serviceEngine = null;

    public function setServiceAppChanged($appId) {
        $this->isAppChanged[$appId] = TRUE;
    }

    public function setOperationChanged($operationId) {
        $this->isOppChanged[$operationId] = TRUE;
    }

    public function getServiceApp($appId, $isUsePool = TRUE) {

        if ($appId == 1 || $appId == "1" || $appId == "BServiceEngine") {
            if ($this->serviceEngine == NULL) {
                $this->serviceEngine = new BServiceEngine();
            }
            return $this->serviceEngine;
        }

        if (!isset($this->sApps[$appId]) || $this->sApps[$appId] == NULL ||
                !$isUsePool || (isset($this->isAppChanged[$appId]) && $this->isAppChanged[$appId])) {

            if (is_numeric($appId))
                $this->sApps[$appId] = BServiceApp::getInstanceById($appId);
            else {
                $this->sApps[$appId] = new $appId();
            }
        }


        return $this->sApps[$appId];
    }

    public function getOperation($operationId) {

        if (!isset($this->opps[$operationId]) || $this->opps[$operationId] == NULL || $this->isOppChanged[$operationId]) {
            $this->opps[$operationId] = new BOperation($operationId);
        }

        return $this->opps[$operationId];
    }

}

?>
